< previous page page_334 next page >

Page 334
The code for creating the body of the button, which should be placed in the UserControl's Paint event, is shown in Listing 14.5.
Listing 14.5 COLORBTN.ZIPUsing the Line Method to Draw the Color Button
Private Sub UserControl_Paint()
    Dim nHeight As Integer
    Dim nWidth  As Integer

    With UserControl

        'Leave some room for the border
        nHeight = .Height - 10
        nWidth = .Width - 10

        'Set UserControl's BackColor, draw a colored box
        .DrawWidth = 1
        .FillColor = lngBackColor
        .FillStyle = 0
        UserControl.Line (0, 0)-(nWidth, nHeight), , B

        'Draw lower right lines
        .DrawWidth = 3
        If bMouseDown = False Then
            .ForeColor = vbBlack
        Else
            .ForeColor = vbWhite
        End If
        UserControl.Line (0, nHeight)-(nWidth, nHeight)
        UserControl.Line (nWidth, 0)-(nWidth, nHeight)

        'Draw upper-left lines
        If bMouseDown = False Then
            .ForeColor = vbWhite
        Else
            .ForeColor = vbBlack
        End If
        UserControl.Line (0, 0)-(nWidth, 0)
        UserControl.Line (0, 0)-(0, nHeight)

        'Calculate and move to the the caption position
        .CurrentX = (.Width - .TextWidth(m_Caption)) / 2
        If .CurrentX < 5 Then .CurrentX = 5
        .CurrentY = (.Height - .TextHeight(m_Caption)) / 2
        If .CurrentY < 5 Then .CurrentY = 5

        'Draw the Caption
        .ForeColor = lngForeColor
        UserControl.Print m_Caption

End With

End Sub
The code in Listing 14.5 should be fairly easy to follow. First, several calls to the Line method are used to draw a box and some lines to represent the command button. Next, the button

 
< previous page page_334 next page >